<!DOCTYPE html>
<html class="loginHtml">
<head>
	<meta charset="utf-8">
	<title>登录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="../../favicon.ico">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css" media="all" />
	<style>
		.fl {
			float: left;
		}
	</style>
</head>
<body class="loginBody">
	<form class="layui-form">
		<div class="login_face"><img src="../../images/face.png" class="userAvatar"></div>
		<div class="layui-form-item input-item">
			<label for="userName">用户名</label>
			<input type="text" placeholder="请输入用户名" autocomplete="off" id="userName" name="username" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" autocomplete="off" id="password" name="password" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item" id="imgCode">
			<label for="code">验证码</label>
			<input type="text" placeholder="请输入验证码" autocomplete="off" id="code" name="code" class="layui-input">
			<img id="cpacha" title="看不清？换一张" style="cursor: pointer" src="/user/getCpacha">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
			<p><a href="register.html" class="fl">立即注册</a></p>
		</div>

	</form>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript" src="login.js"></script>
	<script type="text/javascript" src="../../js/cache.js"></script>
	<script>
        layui.use('form', function(){
            var $ = layui.$;//layui中使用jQuery
            var form = layui.form;
            $("#cpacha").click(function(){
				$("#cpacha").attr("src","/user/getCpacha?t=" + new Date().getTime());
			});

            form.on('submit(login)',function (data){
                $.ajax({
                    url:"/user/login"
                    ,type:"post"
                    ,data:data.field
                    ,success:function(d){
                        if(d === 1){
                            layer.msg('登录中。。。',{
                                icon:1,
                                time:1000//不配置默认3秒
                            }),
                                window.location.href = '/index.html?username='+document.getElementById("userName").value;

                        }else if(d === 2){
                            layer.msg('该用户名不存在，请修改后登录',{
                                icon:5,
                                time:1000//不配置默认3秒
                            });
                        }else if(d === 3){
                            layer.msg('密码输入错误，请重试',{
                                icon:5,
                                time:1000//不配置默认3秒
                            });
                        }else if(d === 4){
							layer.msg('会话超时，请刷新页面',{
								icon:5,
								time:1000//不配置默认3秒
							});
						}else if(d === 5){
							layer.msg('验证码错误，请重新输入',{
								icon:5,
								time:1000//不配置默认3秒
							});
						}
                    }
                });
                return false;
            });
        });
	</script>
</body>
</html>